# -*- coding:utf-8 -*-

import sys
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QMainWindow, QApplication
from ui_pandas_pyqt import Ui_MainWindow

from qtpandas.models.DataFrameModel import DataFrameModel
import pandas as pd


class MainWindow(QMainWindow, Ui_MainWindow):
	def __init__(self, parent=None):
		super(MainWindow, self).__init__(parent)
		self.setupUi(self)
		widget = self.pandastablewidget
		widget.resize(600, 500)
		self.model = DataFrameModel()  # 设置新的模型
		widget.setViewModel(self.model)
		self.df = pd.read_excel(r'./data/fund_data.xlsx')
		self.df_original = self.df.copy()  # 备份原始数据
		self.model.setDataFrame(self.df)

	@pyqtSlot()
	def on_pushButton_clicked(self):
		self.model.setDataFrame(self.df_original)

	@pyqtSlot()
	def on_pushButton_2_clicked(self):
		self.df.to_excel('./data/fund_data_new.xlsx')


if __name__ == '__main__':
	app = QApplication(sys.argv)
	ui = MainWindow()
	ui.show()
	sys.exit(app.exec_())
